package org.dreamfly.core.action;

import org.dreamfly.core.bean.SzPictureType;
import org.dreamfly.core.service.PictureTypeService;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Gin
 * Date: 2010-9-18
 * Time: 10:32:35
 * To change this template use File | Settings | File Templates.
 */
public class PictureTypeAction extends BaseAction {
    private String typeName;
    private SzPictureType pictureType;
    private List<SzPictureType> types;
    private PictureTypeService pictureTypeService;
    private String serverName;

    /**
     * 添加分类
     *
     * @return success 如果添加成功
     */
    public String add() {
        pictureType.setServer(serverName);
        pictureType = pictureTypeService.addIndexURl(pictureType);
        pictureTypeService.saveOrUpdate(pictureType);
        return null != pictureType.getTypeId() ? SUCCESS : INPUT;
    }

    /**
     * 修改图片分类名
     *
     * @return
     */
    public String modify() {

        pictureTypeService.modify(pictureType);
        return SUCCESS;
    }

    /**
     * 删除图片分类
     *
     * @return
     */
    public String delete() {
        pictureTypeService.deleteType(pictureType.getTypeId());
        return SUCCESS;
    }

    /**
     * 搜索所有图片分类
     *
     * @return success 如果查出图片分类列表
     */
    public String searchAll() {
        types = pictureTypeService.getAll();
        return null != types && types.size() != 0 ? SUCCESS : INPUT;
    }

    public String searchAllByServer(){
        types = pictureTypeService.getAllByServer(serverName);
        return null != types && types.size() != 0 ? SUCCESS : INPUT;
    }

    public String getServerName() {
        return serverName;
    }

    public void setServerName(String serverName) {
        this.serverName = serverName;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public List<SzPictureType> getTypes() {
        return types;
    }

    public void setTypes(List<SzPictureType> types) {
        this.types = types;
    }

    public SzPictureType getPictureType() {
        return pictureType;
    }

    public void setPictureTypeService(PictureTypeService pictureTypeService) {
        this.pictureTypeService = pictureTypeService;
    }

    public void setPictureType(SzPictureType pictureType) {
        this.pictureType = pictureType;
    }
}
